<?php

namespace App\Kuafu\Customer\Model;

use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use Illuminate\Database\Eloquent\Builder;
use App\Kuafu\Base\Model\BaseModel;

class CustomerPlatformModel extends BaseModel
{
    use KfSoftDeletes;

    protected $connection = 'mysql';
    protected $table      = 'customer_platform_mappings'; //表名
    protected $fillable   = ['unionid', 'openid', 'platformId', 'userId', 'name', 'headImage'];

    protected $hidden = [
        'updatedAt',
        'isDeleted'
    ];


    /**
     * 添加
     * @param array $data
     * @return Builder|\Illuminate\Database\Eloquent\Model
     */
    public static function addData(array $data)
    {
        return self::query()->create($data);
    }

    /**
     * 通过指定列值查询指定的数据
     * @param $columnValue
     * @param $field
     * @return Builder|\Illuminate\Database\Eloquent\Model|object|null
     */
    public static function getUserInfoByColumn($columnValue, $field)
    {
        return self::query()
                   ->where($columnValue)
                   ->select($field)
                   ->first();
    }

    public static function setData($unionid, $platformId, $value)
    {
        return self::query()->where(['unionid' => $unionid, 'platformId' => $platformId])
                   ->update($value);
    }
}
